package com.kycxika.app.utils;

import android.content.SharedPreferences;
import com.kycxika.app.KycXikaApplication;

import static android.content.Context.MODE_PRIVATE;

/**
 * Created by Administrator on 2017/5/5.
 */

public class SharedPreferencesHelp {
    public static SharedPreferencesHelp sharedPreferencesHelp;

    public String AUTOMATIC_LOGON ="AUTOMATIC_LOGON";
    public String LOGON_STATUS ="LOGON_STATUS";
    public String REMEMBER_PASSWORD = "REMEMBER_PASSWORD";
    public String UserAccessTokne = "UserAccessTokne";


    private SharedPreferences sp;
    private SharedPreferences.Editor editor;
    private String LoginUsername = "LoginUsername";
    private String LoginPassword = "LoginPassword";

    private String isFirstLogin = "isFirstLogin";
    private String version = "version";
    private String updateFile = "updateFile";
    private String updateBook = "updateBook";
    private String USERHEADER = "USERHEADER";
    private String USERID = "USERID";
    private String USER_NIKE = " user_nike";
    private String USER_SEX = "USER_SEX";

    public SharedPreferencesHelp(){
        sp = KycXikaApplication.getInstance().getSharedPreferences("sp",MODE_PRIVATE);
        editor = sp.edit();
    }


    public static SharedPreferencesHelp getInstance(){
        if(sharedPreferencesHelp == null){
            sharedPreferencesHelp = new SharedPreferencesHelp();
            return sharedPreferencesHelp;
        }else {
            return sharedPreferencesHelp;
        }
    }

    public void saveLoginStatus(boolean logon){
        editor.putBoolean(LOGON_STATUS, logon);
        editor.apply();
    }

    public boolean getLoginStatus(){
        return sp.getBoolean(LOGON_STATUS,false);
    }


    /**
     * 是否自动登录
     * @param logon
     */

    public void saveAutomaticLogon(boolean logon){
        editor.putBoolean(AUTOMATIC_LOGON, logon);
        editor.apply();
    }

    public boolean getAutomaticLogon(){
        return sp.getBoolean(AUTOMATIC_LOGON,false);
    }

    /**
     * 是否记住密码
     * @param save
     */

    public void saveRememberPassword(boolean save){
        editor.putBoolean(REMEMBER_PASSWORD, save);
        editor.apply();
    }

    public boolean getRememberPassword(){
        return sp.getBoolean(REMEMBER_PASSWORD,false);
    }


    public void saveUserAccessTokne(String name){
        editor.putString(UserAccessTokne,name);
        editor.apply();
    }

    public String getUserAccessToken(){
        return sp.getString(UserAccessTokne,"");
    }

    public void saveLoginUsername(String name){
        editor.putString(LoginUsername,name);
        editor.apply();
    }
    public String getLoginUsername(){
        return sp.getString(LoginUsername,"");
    }


    public void saveUserID(int userID){
        editor.putInt(USERID,userID);
        editor.apply();
    }
    public int getUserID(){
        return sp.getInt(USERID,-1);
    }

    public void saveUserNick(String userNike){
        editor.putString(USER_NIKE,userNike);
        editor.apply();
    }
    public String getUserNick(){
        return sp.getString(USER_NIKE,"");
    }

    public void saveUserSex(int usersex){
        editor.putInt(USER_SEX,usersex);
        editor.apply();
    }
    public int getUserSex(){
        return sp.getInt(USER_SEX,-1);
    }

    public void saveisFirstLogin(boolean name){
        editor.putBoolean(isFirstLogin,name);
        editor.apply();
    }

    public void saveLoginPassword(String name){
        editor.putString(LoginPassword,name);
        editor.apply();
    }

    public String getLoginPassword(){
        return sp.getString(LoginPassword,"");
    }

    public boolean getisFirstLogin(){
        return sp.getBoolean(isFirstLogin,false);
    }

    /**
     *
     */
    public void saveLoginType(int  loginType){
        editor.putInt("loginType", loginType);
        editor.apply();
    }

    public int getloginType(){
        return sp.getInt("loginType",1);
    }

    public void saveVersionUpdate(String name){
        editor.putString(version,name);
        editor.apply();
    }
    public String getVersionUpdate(){
        return sp.getString(version,"");
    }

    public void saveUpdateFile(String name){
        editor.putString(updateFile,name);
        editor.apply();
    }
    public String getUpdateFile(){
        return sp.getString(updateFile,"");
    }

    public void saveUpdateBookCard(String name) {
        editor.putString(updateBook,name);
        editor.apply();
    }
    public String getUpdateBookCard(){
        return sp.getString(updateBook,"");
    }

    public void saveUserHeader(String name) {
        editor.putString(USERHEADER,name);
        editor.apply();
    }
    public String getUserHeader(){
        return sp.getString(USERHEADER,"");
    }
}
